Okay so lets quickly recap where we are at with this project:
And finally, let's quickly consider what we have left to do:
Today we shall be focus on the reveal square function.
Okay, so here's the basic implementation idea. When we start a new game we create two boards:
The player board will have the same dimensions as the game board. This means that the square (0, 0) on the game board corressponds to same square on the player board. You may remember that when we wrote the 'build_board' function I advised you to make it generalisable. Well, the effort is about to pay-off; we can create both of our boards with just a few lines of code:
In [ ]:
NUMBER_OF_ROWS = 3
NUMBER_OF_COLS = 3
NUMBER_OF_BOMBS = 2 # You may remember that all_caps mean that these variables should NOT change values at runtime.
game_board = build_board(NUMBER_OF_ROWS, NUMBER_OF_COLS, bomb_count = NUMBER_OF_BOMBS)
player_board = build_board(NUMBER_OF_ROWS, NUMBER_OF_COLS, bomb_count=0)
Also note that if the player flags all (and only) bombs then the player has won the game. You may wish to bear that in mind as you write your functions...
Also as you read the requirements it should hopefully occur to you that the flag and reveal square functions are actually rather similar. What do this mean? What should you do as a result of this similiarity?
In [ ]:
def test_board():
"""
Write your tests here...
Example:
>>> 1 + 1
2
"""
import doctest
doctest.testmod()
print("TESTING COMPLETE... if you see nothing, (other than this message) that means all tests passed.")
In [ ]:
def reveal_square(row, col, player_board, game_board):
# Your code here...
pass
# testing...
test()
In [ ]:
def flag_square(row, col, player_board):
# Your code here...
pass
# testing...
test()